﻿
''' <summary>
''' Maps the ArgumentTypes to ArgHandlers, and ArgListTypes to ArgListHandlers
''' </summary>
''' <remarks></remarks>
Public Class ArgumentManager
#Region "Singleton"
    Private Shared mInstance As ArgumentManager
    Public Shared ReadOnly Property instance As ArgumentManager
        Get
            Return mInstance
        End Get
    End Property

    Shared Sub New()
        mInstance = New ArgumentManager
    End Sub
#End Region

    Private mArgTypeParsers As Dictionary(Of ArgType, IArgHandler)
    Private mArgsListTypeParsers As Dictionary(Of ArgsType, IArgsTypeHandler)

    Private Sub New()
        mArgTypeParsers = New Dictionary(Of ArgType, IArgHandler)
        mArgTypeParsers.Add(ArgType.Bit, New NullArgHandler)
        mArgTypeParsers.Add(ArgType.ColorNumber, New ColorNumberArgHandler)
        mArgTypeParsers.Add(ArgType.DegreesUrist, New DegreesUristArgHandler)
        mArgTypeParsers.Add(ArgType.Integer, New IntegerArgHandler)
        mArgTypeParsers.Add(ArgType.List, New ListArgHandler)
        mArgTypeParsers.Add(ArgType.Lookup, New LookupArgHandler)
        mArgTypeParsers.Add(ArgType.String, New StringArgHandler)
        mArgTypeParsers.Add(ArgType.CharCode, New CharCodeArgHandler)
        mArgTypeParsers.Add(ArgType.Decimal, New DecimalArgHandler)
        mArgTypeParsers.Add(ArgType.Material, New MaterialArgHandler)
        mArgTypeParsers.Add(ArgType.Item, New ItemArgHandler)
        mArgTypeParsers.Add(ArgType.Building, New BuildingArgHandler)
        mArgTypeParsers.Add(ArgType.Skill, New SkillArgHandler)
        mArgTypeParsers.Add(ArgType.ToolUse, New ToolUseArgHandler)
        mArgTypeParsers.Add(ArgType.BodyGloss, New BodyGlossArgHandler)
        mArgTypeParsers.Add(ArgType.Labor, New LaborArgHandler)
        mArgTypeParsers.Add(ArgType.ColorTriplet, New ColorTripletArgHandler)
        mArgTypeParsers.Add(ArgType.Sphere, New SphereArgHandler)

        mArgsListTypeParsers = New Dictionary(Of ArgsType, IArgsTypeHandler)
        mArgsListTypeParsers.Add(ArgsType.Standard, New StandardArgsHandler)
        mArgsListTypeParsers.Add(ArgsType.List, New ListArgsHandler)
    End Sub

    Public Function GetArgTypeHandler(argumentType As ArgType) As IArgHandler
        If mArgTypeParsers.ContainsKey(argumentType) Then
            Return mArgTypeParsers(argumentType)
        Else
            Throw New NoArgHandlerFoundException(argumentType)
        End If
    End Function

    Public Function GetArgsTypeHandler(argsListType As ArgsType) As IArgsTypeHandler
        If mArgsListTypeParsers.ContainsKey(argsListType) Then
            Return mArgsListTypeParsers(argsListType)
        Else
            Throw New NoArgListTypeHandlerFoundException(argsListType)
        End If
    End Function

    Public Function GetArgsTypeHandler(usage As TokenUsage) As IArgsTypeHandler
        If usage IsNot Nothing Then
            Return GetArgsTypeHandler(usage.ArgsType)
        Else
            Return mArgsListTypeParsers(ArgsType.Standard)
        End If
    End Function
End Class
